package com.tdtxdcxm.ruralcommunity.providers;

import com.tdtxdcxm.ruralcommunity.appruntime.DataCenterControl;
import com.tdtxdcxm.ruralcommunity.slice.MainAbilitySlice;
import com.tdtxdcxm.ruralcommunity.webviewconfig.SetWebAgent;
import com.tdtxdcxm.ruralcommunity.webviewconfig.SetWebConfig;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;
import ohos.agp.components.webengine.WebView;

import java.util.ArrayList;

public class PSProvider extends PageSliderProvider {
    private AbilitySlice abilitySlice;
    private ArrayList arrayList;
    private int typeN;
    public PSProvider(AbilitySlice abilitySlice,ArrayList arrayList,int tabCount,int typeN) {
        this.abilitySlice = abilitySlice;
        this.arrayList = arrayList;
        this.typeN = typeN;
        DataCenterControl.addDataToPagesList(abilitySlice,tabCount,typeN);//把pageslider每一页填上布局组件
    }

    @Override
    public int getCount() {
        return arrayList != null ? arrayList.size() : 0;
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        DirectionalLayout directionalLayout = (DirectionalLayout) arrayList.get(i); //这里面放的是每个tab的子布局
        if(typeN == 3 && i == 0){
            //MyTools.toastShow("this is webview!", abilitySlice.getContext());
            WebView webView = (WebView) directionalLayout.getComponentAt(0);
            DataCenterControl.webView = webView;
            SetWebConfig.setWebViewConfig(webView);
            SetWebAgent setWebAgent = new SetWebAgent("http://81.69.9.126:8890/");
            webView.setWebAgent(setWebAgent);
        }
        componentContainer.addComponent(directionalLayout);

        if(typeN == 0 || typeN == 1){
            ListContainer listContainer = (ListContainer) directionalLayout.getComponentAt(0);
            if(typeN == 0){
                switch(i){
                    case 0:
                        MainAbilitySlice.initListContainer(listContainer, "worlddtlc",abilitySlice, typeN,i);
                        break;
                    case 1:
                        MainAbilitySlice.initListContainer(listContainer, "worldxmlc",abilitySlice, typeN,i);
                        break;
                    case 2:
                        MainAbilitySlice.initListContainer(listContainer, "worldwzlc",abilitySlice, typeN,i);
                        break;
                    default:
                        break;
                }
            }
            if(typeN == 1){
                switch(i){
                    case 0:
                        MainAbilitySlice.initListContainer(listContainer, "artlc",abilitySlice, typeN,i);
                        break;
                    case 1:
                        MainAbilitySlice.initListContainer(listContainer, "clothelc",abilitySlice, typeN,i);
                        break;
                    case 2:
                        MainAbilitySlice.initListContainer(listContainer, "foodlc",abilitySlice, typeN,i);
                        break;
                    case 3:
                        MainAbilitySlice.initListContainer(listContainer, "houselc",abilitySlice, typeN,i);
                        break;
                    case 4:
                        MainAbilitySlice.initListContainer(listContainer, "trafficlc",abilitySlice, typeN,i);
                        break;
                    case 5:
                        MainAbilitySlice.initListContainer(listContainer, "studylc",abilitySlice, typeN,i);
                        break;
                    case 6:
                        MainAbilitySlice.initListContainer(listContainer, "culturelc",abilitySlice, typeN,i);
                        break;
                    default:
                        break;
                }
            }
        }
        if(typeN == 3 && i != 0){
            ListContainer listContainer = (ListContainer) directionalLayout.getComponentAt(0);
            switch(i){
                case 0:
                    break;
                case 1:
                    MainAbilitySlice.initListContainer(listContainer, "messageagreelc",abilitySlice, typeN,i);
                    break;
                case 2:
                    MainAbilitySlice.initListContainer(listContainer, "messagediscusslc",abilitySlice, typeN,i);
                    break;
                case 3:
                    MainAbilitySlice.initListContainer(listContainer, "messagecollectlc",abilitySlice, typeN,i);
                    break;
                default:
                    break;
            }
        }


        return directionalLayout;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return false;
    }
}
